package nl.unimaas.group11.project1_3.algo;

import java.awt.Frame;
import nl.unimaas.group11.project1_3.Initialise;
import nl.unimaas.group11.project1_3.Main;
import nl.unimaas.group11.project1_3.graphics.Render;


public class DataProcessor {

	public static int containerX, containerY, containerZ, valueA, valueB, valueC, seconds;
	
	public static boolean pents;
	public static boolean algoHasRun=false;
	public static long solutionTime;
	public static double maxValue, percent;
	public static int[][][]solutionCopy;
	//public int[][][] container = new int[12][6][6];

	public DataProcessor(boolean pents, int algo, int containerX, int containerY, int containerZ, int valueA, int valueB, int valueC, int seconds) {

		DataProcessor.containerX=containerX;
		DataProcessor.containerY=containerY;
		DataProcessor.containerZ=containerZ;
		DataProcessor.valueA=valueA;
		DataProcessor.valueB=valueB;
		DataProcessor.valueC=valueC;
		DataProcessor.seconds=seconds;
		
		
		
		
		
		
		int[][][]solution;
		if(pents){
			Bruteforce pentsBruteforce = new Bruteforce(valueA, valueB, valueC, containerX, containerY, containerZ);
			pentsBruteforce.start(true, false, 1);
			solution = pentsBruteforce.bestSolution;
			DataProcessor.pents=true;
			solutionTime=pentsBruteforce.endTime-pentsBruteforce.startTime;
			maxValue=pentsBruteforce.maxValue;
		}
		else if (algo==1){
			Bruteforce boxesBruteforce = new Bruteforce(valueA, valueB, valueC, containerX, containerY, containerZ);
			boxesBruteforce.start(false,true,seconds);
			solution = boxesBruteforce.bestSolution;
			DataProcessor.pents=false;
			solutionTime=boxesBruteforce.endTime-boxesBruteforce.startTime;
			maxValue=boxesBruteforce.maxValue;
		}else{
			
			//int boxAValue, int boxBValue, int boxCValue, int containerX, int containerY, int containerZ, int seconds
			Greedy boxesGreedy = new Greedy(valueA, valueB, valueC, containerX, containerY, containerZ);
			boxesGreedy.start(seconds);
			solution = boxesGreedy.solution;
			DataProcessor.pents=false;
			solutionTime=boxesGreedy.greedy.endTime-boxesGreedy.greedy.startTime;
			maxValue=boxesGreedy.greedy.maxValue;

		}
		
		solutionCopy=solution;
		

		
		
		percent = returnPercentFilled(solution);
		
		int temp=(int)((percent*Math.pow(10,3)));

		percent = (((double)temp)/Math.pow(10,3));
			
		
		
		if(algoHasRun){
			Main.init.gui.setState(Frame.ICONIFIED);
			Main.init.gui = new Render();
			Main.init.updateRightPanel();
		}else{
			algoHasRun=true;
			Main.init.updateRightPanel();

			//Main.init.gui.rightPane.repaint();
		
		}
		Initialise.rightFrameExists=true;
		
		Main.init.gui.world3d.draw3DSolution(solution);
		
		
	}


	
	public void start(){//start is a temp name, will change it to a better one later

	}

	public double returnPercentFilled(int[][][] container){
		
		int totalVolume=(container.length*container[0].length*container[0][0].length);
		int unitsFilled = 0;
		
		for(int x = 0;x<container.length;x++){
			for(int y = 0;y<container[0].length;y++){
				for(int z = 0;z<container[0][0].length;z++){
					if(container[x][y][z]!=0){
						unitsFilled++;
					}
				}
			}
		}

		return ((double)unitsFilled)/totalVolume*100;
	}

}
